package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.utils.threadlocal.UserThreadLocal;
import com.zzyl.nursing.domain.member.Reservation;
import com.zzyl.nursing.dto.member.ReservationDto;
import com.zzyl.nursing.service.member.MemberReservationService;
import com.zzyl.nursing.vo.member.CreateByTimeVo;
import com.zzyl.nursing.vo.member.ReservationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags =  "预约信息相关接口")
public class MemberReservationController extends BaseController
{
    @Autowired
    private MemberReservationService memberReservationService;
    /**
     * 2.1 查询当天取消预约数量
     */
    @GetMapping("/cancelled-count")
    public R<String> getCancelCount() {
        Integer result = memberReservationService.getCancelCount();
        String date = String.valueOf(result);
        return R.ok("操作成功");
    }
    /**
     * 2.2 查询每个时间段剩余预约次数
     */
    @GetMapping("/countByTime")
    public R<List<CreateByTimeVo>> getCountByTime() {
        List<CreateByTimeVo> result = memberReservationService.getCountByTime();
        return R.ok(result);
    }
    /**
     * 2.3新增预约
     */
    @PostMapping
    @ApiOperation("新增预约")
    public R<String> add(@RequestBody ReservationDto dto) {
        boolean flag = memberReservationService.add(dto);
        return flag ? R.ok("操作成功") : R.fail("操作失败");
    }
    /**
     * 列表查询预约
     */
    @GetMapping("/page")
    @ApiOperation("列表查询预约")
    public AjaxResult listPage(
            Integer pageNum,
            Integer pageSize,
            Integer  status) {
        ReservationVo result =memberReservationService.findByPage(pageNum,pageSize,status);
        return AjaxResult.success("操作成功",result);
    }
    /**
     * 取消预约
     */
    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public R<String> cancel(@PathVariable Long id) {
        boolean flag = memberReservationService.cancel(id);
        return flag ? R.ok("操作成功") : R.fail("操作失败");
    }
}